﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DoModelExample
{
    public class StationRange
    {
        // 起点里程
        public double m_StartStation { get; set; } = 0;

        // 终点里程
        public double m_EndStation { get; set; } = 0;

        public StationRange(double station_S, double station_E)
        {
            m_StartStation = station_S;
            m_EndStation = station_E;
        }

        public double StationRangeLength()
        {
            // Need Check: 桩号差距，即路线上的长度. 单位为 m
            return (m_EndStation - m_StartStation);
        }

        public List<double> Samples(double dInterval)
        {

            if (StationRangeLength() < ConstDef.Eps_Len_Meter
                || dInterval < ConstDef.Eps_Len_Meter)
            {
                return new List<double>();
            }

            double dS = this.m_StartStation;
            int N = (int)(StationRangeLength() / dInterval + 0.0001);//避免0.9999不等于1的情况

            // dS
            List<double> vecStations = new List<double>(N+2) { dS };

            // mid
            for (int i = 1; i <= N; ++i)
            {
                vecStations.Add(dS + i * dInterval);
            }

            // end
            double dE = this.m_EndStation;
            if ((dE - vecStations.Last()) > ConstDef.Eps_Len_Meter) // fix:  不添加重复截面
            {
                vecStations.Add(m_EndStation);
            }

            return vecStations;
        }

    }
}
